package String;

public class p1768交替合并字符串 {
    class Solution {
        public String mergeAlternately(String word1, String word2) {
            int len1 = word1.length();
            int len2 = word2.length();
            int minLen = Math.min(len1, len2);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < minLen; i++) {
                sb.append(word1.charAt(i));
                sb.append(word2.charAt(i));
            }
            if (len1 > len2){
                for (int i = 0; i < len1 - minLen; i++) {
                    sb.append(word1.charAt(minLen + i));
                }
            }
            if (len1 < len2){
                for (int i = 0; i < len2 - minLen; i++) {
                    sb.append(word2.charAt(minLen + i));
                }
            }
            return sb.toString();
        }
    }
}
